class MyPageHeader extends BaseEditMaster {
    constructor(dataId, currentTaskPrivileges, nextTaskPrivileges, pageStatus, pageListData,
            returnUrl, fetchDataUrl, saveUrl, exportUrl, printUrl) {
        super(dataId, currentTaskPrivileges, nextTaskPrivileges, pageStatus, pageListData,
                returnUrl, fetchDataUrl, saveUrl, exportUrl, printUrl);
    }
    // 得到发货发令单数据
    GetEntityData() {
        let item = {};
        item['headerId'] = $("#HeaderId").val();
        item['billNo'] = $.trim($("#BillNo").val());                    // 发货发令单号（自动生成）
        item['customerId'] = $.trim($("#CustomerId").val());            // 客户         
        item['dateOfDelivery'] = $.trim($("#DateOfDelivery").val());    // 日期
        item['responsibleBy'] = $.trim($("#ResponsibleBy").val());      // 负责人
        item['destination'] = $.trim($("#Destination").val());          // 目的港
        item['shippingTypeId'] = $.trim($("#ShippingTypeId").val());                      // 运输方式
        item['isAssortedColour'] = $("#IsAssortedColour").is(":checked") ? true : false;  // 可混色
        item['isAssortedSize'] = $("#IsAssortedSize").is(":checked") ? true : false;      // 可混码
        item['isNewNoPerDestination'] = $("#IsNewNoPerDestination").is(":checked") ? true : false;  // 每发货地重新编号
        item['isNewNoPerColour'] = $("#IsNewNoPerColour").is(":checked") ? true : false;            // 每色重新编号
        item['description'] = formatNullInputValue($.trim($("#Description").val()));      // 备注
        item['createdBy'] = $.trim($("#UserId").val());
        item['updatedBy'] = $.trim($("#UserId").val());

        return JSON.stringify(item);
    }
    FillData(data) {
        let item = data.HeaderEntity;
        $("#HeaderId").val(item.headerId);
        $("#BillNo").val(item.billNo);
        $("#DateOfDelivery").val(item.dateOfDelivery);
        $("#CustomerId").val(item.customerId);
        $("#CustomerName").val(item.customerName);
        $("#ResponsibleBy").val(item.responsibleBy);
        $("#ResponsibleByName").val(item.responsibleByName);
        $("#Destination").val(item.destination);
        $("#ShippingTypeId").val(item.shippingTypeId);
        $("#ShippingTypeName").val(item.shippingTypeName);
        $("#SoNo").val(item.soNo);
        $("#UpdatedByName").val(item.updatedByName);
        $("#UpdatedDate").val(formatNullData(item.updatedDate));
        $("#Description").val(item.description);
        if (item.isAssortedColour) {
            $("#IsAssortedColour").prop("checked", true);
        } else {
            $("#IsAssortedColour").prop("checked", false);
        }
        if (item.isAssortedSize) {
            $("#IsAssortedSize").prop("checked", true);
        } else {
            $("#IsAssortedSize").prop("checked", false);
        }
        if (item.isNewNoPerDestination) {
            $("#IsNewNoPerDestination").prop("checked", true);
        } else {
            $("#IsNewNoPerDestination").prop("checked", false);
        }
        if (item.isNewNoPerColour) {
            $("#IsNewNoPerColour").prop("checked", true);
        } else {
            $("#IsNewNoPerColour").prop("checked", false);
        }
        // 最后的审核人、审核日期
        $("#CheckedBy").val(item.checkedBy);
        $("#CheckedByName").val(item.checkedByName);
        $("#CheckedDate").val(item.checkedDate === null ? '' : item.checkedDate);
        $("#CheckedStatus").val(item.checkedStatus);
        $('#FlowOrderNo').val(item.flowOrderNo);

        // 设置用于控制的用户ID
        this.privateUserId = item.updatedBy;

        // 显示明细数据
        _InstancePageLines.BuildDataTable(data.LinesList);
        _InstancePageLinesMo.BuildDataTable(data.LinesMoList);

        this.currentTaskPrivileges = item.currentTaskPrivileges;
        this.nextTaskPrivileges = item.nextTaskPrivileges;
        this.unCheckFlag = item.unCheckFlag;
        this.SetPageElementStatus(this.HidePageElement, this.ShowPageElement, function () {
            _InstancePageLines.AutoAdjustTableHeightForLines();
            _InstancePageLinesMo.AutoAdjustTableHeightForLines();
        });
        $("#BillNo").focus();
    }
    Save() {
        super.Save(function (data, _this) {
            if (data > 0) {
                if (parseInt(_this.pageStatus) === 1) {
                    $("#HeaderId").val(data);   // 设置刚才插入的记录ID
                    $("#Action").val(2);
                    _this.dataId = data;
                    _this.pageStatus = 2;
                    $("#panelSlave").show();
                    $("#ButPrint").show();
                    $("#CheckedTip").removeClass().addClass("huzo_status").addClass("huzo_status__red");
                    $("#CheckedTip").html("状态：未审核");
                    $("#CheckedTip").show();
                }
            }
        });
    }
    New() {
        super.New();
        $("#panelSlave").hide();
        $("#ResponsibleBy").val($("#UserId").val());
        $("#ResponsibleByName").val($("#UserName").val());
        this.FetchNewBillNo();
        $("#BillNo").focus();
    }
    FetchNewBillNo() {
        super.DoAjax(null, "/trade/delivery_command_sheet/header/fetchNewBillNo.html", function (data, $self) {
            $("#BillNo").val(data.BillNo);
        });
    }
    DoChoiceCustomer() {
        let _choice = new CommonChoice();
        let params = {};
        params['Flag'] = 0;
        params['CurrentUserId'] = null;
        params['NotInGroupId'] = null;
        _choice.DoChoiceCustomer(params, "选择客户", (data) => {
            if (data) {
                // 判断是否数据发生了改变如果改变则设置改变标记
                if ($("#CustomerName").val() !== data[1]) {
                    $("#form_data").data("changed", true);
                }
                $("#CustomerId").val(data[0]);
                $("#CustomerName").val(data[1]);
            }
        });
    }
    DoChoiceResponsibleBy() {
        let _choice = new CommonChoice();
        _choice.DoChoiceUser(0, '选择负责人', '贸易', (data) => {
            if (data) {
                // 判断是否数据发生了改变如果改变则设置改变标记
                if ($("#ResponsibleByName").val() !== data[1]) {
                    $("#form_data").data("changed", true);
                }
                $("#ResponsibleBy").val(data[0]);
                $("#ResponsibleByName").val(data[1]);
            }
        });
    }
    DoChoiceShippingType() {
        let _choice = new CommonChoice();
        _choice.DoChoiceShippingType(0, (data) => {
            if (data) {
                // 判断是否数据发生了改变如果改变则设置改变标记
                if ($("#ShippingTypeName").val() !== data[1]) {
                    $("#form_data").data("changed", true);
                }
                $("#ShippingTypeId").val(data[0]);
                $("#ShippingTypeName").val(data[1]);
            }
        });
    }
    ShowPageElement() {
        $("Button.act__save").show();
        if (!$("span.act__delete").hasClass("act__delete")) {
            $("span.act__delete").addClass("trash");
            $("span.act__delete i").addClass("fa-all fa-trash-o fa-1");
        }
    }
    HidePageElement() {
        $("Button.act__save").hide();
        $("span.act__delete").removeClass("trash");
        $("span.act__delete i").removeClass("fa-all fa-trash-o fa-1");
    }
    Expand() {
        super.Expand(function () {
            // 自适应高度
            _InstancePageLines.AutoAdjustTableHeightForLines();
            _InstancePageLinesMo.AutoAdjustTableHeightForLines();
        });
    }
    /* 折叠 */
    Collapse() {
        super.Collapse(function () {
            // 自适应高度
            _InstancePageLines.AutoAdjustTableHeightForLines();
            _InstancePageLinesMo.AutoAdjustTableHeightForLines();
        });
    }
}

//------------------------------------------------------------------------------
// 本次发货生产情况
//------------------------------------------------------------------------------
class MyPageLinesMo extends BaseEditSlave {
    constructor() {
        super('', '', '');
    }
    BuildDataTable(result) {
        $("#tabData11 tbody").empty();
        // 得到数据列表
        if (result === null || result.length === 0) {    // 批量删除(全部删)后返回的数组长度为0
            $("#panelSlave").show();
            this.rows = 0;
            this.AutoAdjustTableHeightForLines();
            return false;
        }
        let content = '';
        this.rows = result.length;        // 设置表格记录数
        this.numCheckbox = result.length;  // 设置表格记录数
        for (let i = 0; i < result.length; i++) {
            content += '<tr _mash_id="' + result[i].linesId + '" _mash_moheaderid="' + result[i].moHeaderId + '">';
            content += '<td style="text-align:center;">' + (i + 1) + '</td>';
            //if ($("#ActionAcl_4").length === 0 || parseInt($("#ActionAcl_4").val() === 0)) {
            //    content += '<td></td>';
            //} else {
            content += '<td class="column__action"><span title="删除" class="trash act__delete" onclick="_InstancePageLinesMo.DeleteLines(\'' + result[i].linesId + '\',$(this));"><i class="fa-all fa-trash-o fa-1"></i></span></td>';
            //}
            content += '<td>' + formatNullData(result[i].soNo) + '</td>';
            content += '<td>' + formatNullData(result[i].customerName) + '</td>';
            content += '<td>' + formatNullData(result[i].styleNo) + '</td>';
            if (result[i].deliveryDateCtrlMark === true) {
                content += '<td style="text-align:center;"><input type="checkbox" checked="checked" class="checkbox" name="_check_date_control_mark" onclick="$(this).parent().addClass(\'dirty\');"/></td>';
            }
            if (result[i].deliveryDateCtrlMark === false) {
                content += '<td style="text-align:center;"><input type="checkbox" class="checkbox" name="_check_date_control_mark" onclick="$(this).parent().addClass(\'dirty\');"/></td>';
            }
            if (result[i].destinationCtrlMark === true) {
                content += '<td style="text-align:center;"><input type="checkbox" checked="checked" class="checkbox" name="_check_destination_control_mark" onclick="$(this).parent().addClass(\'dirty\');"/></td>';
            }
            if (result[i].destinationCtrlMark === false) {
                content += '<td style="text-align:center;"><input type="checkbox" class="checkbox" name="_check_destination_control_mark" onclick="$(this).parent().addClass(\'dirty\');"/></td>';
            }
            content += '</tr>';

            $('#tabData11 tbody').append(content);
            content = '';
        }
        // 设置明细部分高度
        this.AutoAdjustTableHeightForLines();

        setOneTableRowColor("tabData11");
        $("#panelSlave").show();
    }
    // 增加本次发货生产情况记录
    NewLines() {
        let _choice = new CommonChoice();
        _choice.DoChoiceMo(1, '选择生产指示书', (data) => {
            if (data) {
                let _result = [];
                for (let i = 0; i < data.length; i++) {
                    let item = {};
                    item['headerId'] = parseInt($("#HeaderId").val());
                    item['moHeaderId'] = parseInt(data[i].moHeaderId);
                    item['billNo'] = $("#BillNo").val();
                    item['deliveryDate'] = $("#DateOfDelivery").val();    // 用于计算生产数，交付日期与发货日期比较
                    item['deliveryDateCtrlMark'] = false;
                    item['destinationCtrlMark'] = false;
                    item['createdBy'] = parseInt($.trim($("#UserId").val()));
                    item['updatedBy'] = parseInt($.trim($("#UserId").val()));

                    _result.push(item);
                }
                // 保存，根据所选产品，增加本次发货生产情况表记录
                this.ImportMoLinesIntoLines(_result);
            }
        });
    }
    // 新增本次发货生产情况记录,后台同时更新了合同明细表
    ImportMoLinesIntoLines(data) {
        super.DoAjax(data, '/trade/delivery_command_sheet/lines_mo/insert.html', function (data, _this) {
            // 刷新合同明细
            _InstancePageLines.BuildDataTable(data.LinesList);
            // 刷新本次发货生产情况
            _this.BuildDataTable(data.LinesMoList);
            // 更新主合同号
            $("#SoNo").val(data.SoNo);

            ShowSuccessMessagePanel("增加成功。");
        });
    }
    // 获取本次发货生产情况数据
    GetLinesData() {
        let jsonUpdate = [];
        $('#tabData11 tbody').find("tr").each(function () {
            if ($(this).find('td.dirty').length > 0) {
                let item = {};
                item['headerId'] = $("#HeaderId").val();
                item['linesId'] = $(this).attr("_mash_id");
                item['moHeaderId'] = $(this).attr("_mash_moheaderid");
                item['billNo'] = $("#BillNo").val();
                item['soNo'] = $(this).find("td").eq(2).text();
                item['deliveryDate'] = $("#DateOfDelivery").val();    // 用于计算生产数，交付日期与发货日期比较
                if ($(this).find('td').eq(5).find('input').eq(0).prop('checked') === true) {
                    item['deliveryDateCtrlMark'] = true;
                } else {
                    item['deliveryDateCtrlMark'] = false;
                }
                if ($(this).find('td').eq(6).find('input').eq(0).prop('checked') === true) {
                    item['destinationCtrlMark'] = true;
                } else {
                    item['destinationCtrlMark'] = false;
                }
                item['updatedBy'] = $.trim($("#UserId").val());
                jsonUpdate.push(item);
            }
        });
        return JSON.stringify(jsonUpdate);
    }
    // 更新本次发货生产情况
    SaveLines() {
        //step 1、进行页面验证，失败则返回
        let success_01 = CheckGridInput02();
        if (!success_01)
            return;

        super.SaveLines("/trade/delivery_command_sheet/lines_mo/update.html", function (data, $self) {
            if (data.LinesMoList !== undefined) {
                // 刷新本次发货生产情况
                $self.BuildDataTable(data.LinesMoList);
                // 刷新合同明细
                _InstancePageLines.BuildDataTable(data.LinesList);
                // 更新主合同号
                $("#SoNo").val(data.SoNo);
            }

            ShowSuccessMessagePanel("保存成功。");
        });
    }
    // 删除本次发货生产情况
    DeleteLines(linesId, $self) {
        let params = {};
        params['headerId'] = $("#HeaderId").val();
        params['linesId'] = linesId;
        params['moHeaderId'] = $self.parent().parent().attr("_mash_moheaderid");
        params['billNo'] = $("#BillNo").val();
        params['soNo'] = $self.parent().parent().find("td").eq(2).text();
        params['styleNo'] = $self.parent().parent().find("td").eq(4).text();
        params['deletedBy'] = $.trim($("#UserId").val());
        super.DeleteLines(params, "/trade/delivery_command_sheet/lines_mo/delete.html", function (data, $self) {
            if (data.LinesList !== undefined) {
                // 刷新本次发货生产情况
                $self.BuildDataTable(data.LinesMoList);
                // 刷新合同明细
                _InstancePageLines.BuildDataTable(data.LinesList);
                // 更新主合同号
                $("#SoNo").val(data.SoNo);
            }

            ShowSuccessMessagePanel("删除成功。");
        });
    }
    AutoAdjustTableHeightForLines() {
        let h = $(window).height();
        let _tabTop = 0;   // 用于随着窗口变化，下面明细高度随之变化的一个节点
        if ($("#panel_slave_butbar_02").css('display') === 'none') {
            _tabTop = $("#panelSlave").offset().top + 71;
        } else {
            _tabTop = $("#panelSlave").offset().top + 96;
        }
        //$("#test").remove();
        //$(document.body).append('<div id="test" style="background:red;width:100%;position:absolute; top:' + _tabTop + 'px;display:block;height:5px;z-index:10000" />');
        let _rc = Math.floor((h - _tabTop - 15) / 25);
        let _dh = _rc * 25;
        let _rowH = this.rows * 25; // 计算行高
        _dh = (_rowH >= _dh) ? _dh : _rowH;

        $("#divD11").css({"max-height": _dh, height: _dh});
    }
}

//------------------------------------------------------------------------------
// 明细处理部分
//------------------------------------------------------------------------------
class MyPageLines extends BaseEditSlave {
    constructor() {
        super('', '', '');
    }
    BuildDataTable(result) {
        $('#tabData21 tbody').empty();
        // 得到数据列表
        if (result === null || result.length === 0) {
            $("#panelSlave").show();
            this.rows = 0;
            // 自适应高度
            _InstancePageLines.AutoAdjustTableHeightForLines();
            return false;
        }
        let content = '';
        this.rows = result.length;
        this.numCheckbox = result.length;
        for (let i = 0; i < result.length; i++) {
            content += '<tr _mash_id="' + result[i].linesId + '">';
            content += '<td style="padding-left:6px;"><label class="btn" for="R-' + result[i].linesId + '"><input id="R-' + result[i].linesId + '" name="_check_row" type="checkbox" onclick="_InstancePageLines.DoCheckRow($(this), \'_check_row\', $(\'#CheckAll\'));" value="' + result[i].linesId + '"/><i></i><span></span></label></td>';
            content += '<td style="text-align:center;">' + (i + 1) + '</td>';
            content += '<td class="column__action"><span title="删除" class="trash act__delete" onclick="_InstancePageLines.DeleteLines($(this));"><i class="fa-all fa-trash-o fa-1"></i></span></td>';
            content += '<td>' + formatNullData(result[i].destination) + '</td>';
            content += '<td>' + formatNullData(result[i].styleNo) + '</td>';
            content += '<td>' + formatNullData(result[i].productName) + '</td>';
            content += '<td>' + formatNullData(result[i].colourName) + '</td>';
            content += '<td style="text-align:center;">' + formatNullData(result[i].sizeName) + '</td>';
            content += '<td>' + formatNullData(result[i].moQuantity) + '</td>';
            content += '<td>' + result[i].deliveriedQuantity + '</td>';
            content += '<td>' + formatNullData(result[i].moQuantity - result[i].deliveriedQuantity) + '</td>';
            content += '<td class="edited-cell">' + formatNullData(result[i].quantity) + '</td>';
            content += '<td class="edited-cell">' + formatNullData(result[i].shippingMarkNo) + '</td>';
            content += '</tr>';

            $('#tabData21 tbody').append(content);
            content = '';
        }
        // 设置明细部分高度
        this.AutoAdjustTableHeightForLines();

        let _cellid = "_cell__field";
        let _cellname = "__cell__field";
        $('#tabData21 tbody tr').find("td.edited-cell").click(function () {
            OnCellClickEvent($(this), _cellid, _cellname, 0);
        });

        setOneTableRowColor("tabData21");
        $("#panelSlave").show();
    }
    GetLinesData() {
        let jsonUpdate = [];
        $('#tabData21 tbody').find("tr").each(function () {
            if ($(this).find('td.dirty').length > 0) {
                let item = {};
                item['headerId'] = $("#HeaderId").val();
                item['linesId'] = $(this).attr('_mash_id');
                item['quantity'] = $.trim($(this).find('td').eq(11).text());
                item['shippingMarkNo'] = formatNullInputValue($.trim($(this).find('td').eq(12).text()));  // 麦头号               
                item['updatedBy'] = $("#UserId").val();
                jsonUpdate.push(item);
            }
        });

        return JSON.stringify(jsonUpdate);
    }
    SaveLines() {
        //step 1、进行页面验证，失败则返回
        let _success = CheckGridInput02();
        if (!_success)
            return;

        super.SaveLines("/trade/delivery_command_sheet/lines/update.html", function (data, $self) {
            if (data.LinesList !== undefined) {
                // 刷新合同明细
                $self.BuildDataTable(data.LinesList);
            }

            ShowSuccessMessagePanel("保存成功。");
        });
    }
    DeleteLines($self) {
        let params = {};
        params['HeaderId'] = $("#HeaderId").val();
        params['LinesId'] = $self.parent().parent().attr("_mash_id");
        params['LinesData'] = "单据号：" + $("#BillNo").val() +
                "　款号：" + $self.parent().parent().find("td").eq(4).text() +
                "　颜色：" + $self.parent().parent().find("td").eq(5).text() +
                "　尺码：" + $self.parent().parent().find("td").eq(6).text();
        params['DeletedBy'] = $.trim($("#UserId").val());
        super.DeleteLines(params, "/trade/delivery_command_sheet/lines/delete.html", function (data, _this) {
            if (data.LinesList !== undefined) {
                // 刷新合同明细
                _this.BuildDataTable(data.LinesList);
            }

            ShowSuccessMessagePanel("删除成功。");
        });
    }
    GetCheckedLinesData() {
        let jsonresult = {};
        let arrItem = [];
        if ($("input[type='checkbox'][name='_check_row']:checked").length > 0) {
            $("input[type='checkbox'][name='_check_row']:checked").each(function () {
                let $row = $(this).parent().parent().parent();
                let item = {};
                item['headerId'] = $("#HeaderId").val();
                item['linesId'] = $(this).val();
                item['updatedBy'] = $.trim($("#UserId").val());

                arrItem.push(item);
            });
        }

        jsonresult['ItemList'] = arrItem;
        jsonresult['HeaderId'] = $("#HeaderId").val();
        jsonresult['BillNo'] = $("#BillNo").val();
        jsonresult['DeletedBy'] = $.trim($("#UserId").val());
        console.info(JSON.stringify(jsonresult));
        return JSON.stringify(jsonresult);
    }
    BatchDeleteLines() {
        if ($('#tabData21 tbody').find("tr.row__selected").length === 0) {
            ShowErrorMessagePanel("请选择批量删除的记录。");
            return false;
        }
        super.BatchDeleteLines('/trade/delivery_command_sheet/lines/batch_delete.html', function (data, $self) {
            if (data.LinesList !== undefined) {
                // 刷新合同明细
                $self.BuildDataTable(data.LinesList);
            }

            ShowSuccessMessagePanel("删除成功。");
            $("#CheckAll").prop("checked", false);
        });
    }
    // 设置行选择后的状态
    SetRowStatus($self) {
        super.AdjustRowStatus($self, function () {}, function () {});
    }
    // 更改款号顺序
    UpdateLinesStyleNoOrder(){
        showModal(495, 538, '改变款号顺序', parent.basePath + '/trade/delivery_command_sheet/lines/styleno_order/edit.html', null, null);
    }
    AutoAdjustTableHeightForLines() {
        let h = $(window).height();
        let _tabTop = 0;   // 用于随着窗口变化，下面明细高度随之变化的一个节点
        if ($("#panel_slave_butbar_01").css('display') === 'none') {
            _tabTop = $("#panelSlave").offset().top + 71;
        } else {
            _tabTop = $("#panelSlave").offset().top + 96;
        }
        let _rc = Math.floor((h - _tabTop - 15) / 25);
        let _dh = _rc * 25;
        let _rowH = this.rows * 25; // 计算行高
        _dh = (_rowH >= _dh) ? _dh : _rowH;

        $("#divD21").css({"max-height": _dh, height: _dh});
    }
}

var _InstancePageHeader = null;
var _InstancePageLinesMo = null;
var _InstancePageLines = null;

//-----------------------------------------------------------------------------
// 页面初始化
//-----------------------------------------------------------------------------
function onPageReady() {
    let _pageStatus = parseInt($("#Action").val());
    let _dataId = $("#HeaderId").val();

    let delivery_command_sheet_list_result = $.cookie("delivery_command_sheet_list_result") === undefined ? "" : $.cookie("delivery_command_sheet_list_result");
    let _pageListData = [];
    if (delivery_command_sheet_list_result !== "") {
        _pageListData = delivery_command_sheet_list_result.split(',');
        $("#rec_total_rows").text(_pageListData.length);
        $("#rec_cur_row").text($.inArray(_dataId, _pageListData) + 1);

        if (_pageListData.length > 0) {
            let index = $.inArray(_dataId, _pageListData);
            if (index === 0) {
                $("#ButPrev").attr("disabled", "disabled");
            } else {
                $("#ButNext").removeAttr("disabled");
            }
            if (index === (_pageListData.length - 1)) {
                $("#ButNext").attr("disabled", "disabled");
            } else {
                $("#ButPrev").removeAttr("disabled");
            }
        }
    } else {
        $("#rec_total_rows").text("1");
        $("#rec_cur_row").text("1");
    }

    _InstancePageHeader = new MyPageHeader(_dataId, 0, 0, _pageStatus, _pageListData,
            "/trade/delivery_command_sheet/list.html",
            "/trade/delivery_command_sheet/header/fetchByKey.html",
            "/trade/delivery_command_sheet/header/save.html",
            "/trade/delivery_command_sheet/header/export.html",
            "/trade/delivery_command_sheet/print.html");

    _InstancePageLinesMo = new MyPageLinesMo();
    _InstancePageLines = new MyPageLines();

    $("#tabPanelHeader").wxTabs({tabContent: "tabPanelData"});

    window.laydate.render({
        elem: '#DateOfDelivery',
        theme: '#393D49',
        trigger: 'click'
    });

    $("#hPanelSplitter").click(function () {
        if ($(this).children("i").hasClass("fa-angle-double-up")) {
            _InstancePageHeader.Collapse();
        } else {
            _InstancePageHeader.Expand();
        }
    });

    _InstancePageHeader.OnPageLoad();
}

// 画面大小或者位置移动
function onPageResize() {
    if (_InstancePageLines !== null)
        _InstancePageLines.AutoAdjustTableHeightForLines();
    if (_InstancePageLinesMo !== null)
        _InstancePageLinesMo.AutoAdjustTableHeightForLines();
}

//-----------------------------------------------------------------------------
// 验证函数
//-----------------------------------------------------------------------------
$.validator.setDefaults({
    ignore: 'hidden, [reaonly=readonly]'
});
$(function () {
    $("#form_data").validate({
        // Step 1：设置验证规则和错误消息
        rules: {
            _BillNo: "required",
            _DateOfDelivery: {
                dateISO: true,
                required: true
            },
            _CustomerName: "required",
            _ResponsibleByName: "required",
            _Destination: "required",
            _ShippingTypeName: "required"
        },
        messages: {
            _BillNo: "请填写发货发令单号。",
            _DateOfDelivery: {
                dateISO: "请填写正确的日期。",
                required: "请填写发货日期。"
            },
            _CustomerName: "请填写客户。",
            _ResponsibleByName: "请填写负责人。",
            _Destination: "请填写目的港。",
            _ShippingTypeName: "请填写运输方式。"
        },
        // Step 2：设置验证触发事件
        onclick: false,
        onfocusout: false,
        onfocusin: false,
        onkeyup: false,
        onkeydown: false,
        focusInvalid: false,
        // Step 3：设置错误信息提示
        showErrors: window.showErrors  //使用自定义的错误显示方法
    });
});
// 验证输入
function CheckGridInput01() {
    $('#tabData11 tbody').find("tr").each(function () {
        let _fee = $.trim($(this).find('td').eq(4).text()).length > 0 ? $.trim($(this).find('td').eq(4).text()) : 0; //加工费

        if (_fee !== 0) {
            if (!isNumber(_fee)) {
                GridCheckErrHandle($(this), 4, '请输入正确的数字。');
            } else {
                GridCheckSuccessHandle($(this), 4);
            }
        }
    });
    if ($('#tabData11 tbody').find('td.error').length > 0) {
        ShowErrorMessagePanel('对不起，填写的数据有错误。');
        return false;
    } else {
        return true;
    }
}
// 验证输入
function CheckGridInput02() {
    $('#tabData21 tbody').find("tr").each(function () {
        let _quantity = $.trim($(this).find('td').eq(10).text()).length > 0 ? $.trim($(this).find('td').eq(10).text()) : 0; // 数量

        if (_quantity !== 0) {
            if (!isNumber(_quantity)) {
                GridCheckErrHandle($(this), 10, '请输入正确的数字。');
            } else {
                GridCheckSuccessHandle($(this), 10);
            }
        }
    });

    if ($('#tabData21 tbody').find('td.error').length > 0) {
        ShowErrorMessagePanel('对不起，填写的数据有错误。');
        return false;
    } else {
        return true;
    }
}
function GridCheckErrHandle($row, index, errMsg) {
    $row.find('td').eq(index).addClass("error");
    $row.find('td').eq(index).attr('title', errMsg);
}
function GridCheckSuccessHandle($row, index) {
    $row.find('td').eq(index).removeClass("error");
    $row.find('td').eq(index).attr('title', '');
}